home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectMusic / SimpleAudioPath / frmSimple.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  12.1 KB  |  355 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmSimple 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Simple Audio Path"
  6.    ClientHeight    =   4380
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   7245
  10.    Icon            =   "frmSimple.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4380
  15.    ScaleWidth      =   7245
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin VB.Frame Frame3 
  18.       Caption         =   "Description"
  19.       Height          =   1695
  20.       Left            =   3660
  21.       TabIndex        =   17
  22.       Top             =   2220
  23.       Width           =   3495
  24.       Begin VB.Label lbl 
  25.          BackStyle       =   0  'Transparent
  26.          Caption         =   $"frmSimple.frx":0442
  27.          Height          =   1335
  28.          Index           =   4
  29.          Left            =   60
  30.          TabIndex        =   18
  31.          Top             =   240
  32.          Width           =   3375
  33.       End
  34.    End
  35.    Begin VB.Frame Frame2 
  36.       Caption         =   "3D Positioning of AudioPath"
  37.       Height          =   1695
  38.       Left            =   60
  39.       TabIndex        =   6
  40.       Top             =   2220
  41.       Width           =   3555
  42.       Begin MSComctlLib.Slider sldX 
  43.          Height          =   195
  44.          Left            =   300
  45.          TabIndex        =   10
  46.          Top             =   420
  47.          Width           =   2595
  48.          _ExtentX        =   4577
  49.          _ExtentY        =   344
  50.          _Version        =   393216
  51.          LargeChange     =   2
  52.          Min             =   -20
  53.          Max             =   20
  54.          TickFrequency   =   4
  55.       End
  56.       Begin MSComctlLib.Slider sldY 
  57.          Height          =   195
  58.          Left            =   300
  59.          TabIndex        =   11
  60.          Top             =   840
  61.          Width           =   2595
  62.          _ExtentX        =   4577
  63.          _ExtentY        =   344
  64.          _Version        =   393216
  65.          LargeChange     =   2
  66.          Min             =   -20
  67.          Max             =   20
  68.          TickFrequency   =   4
  69.       End
  70.       Begin MSComctlLib.Slider SldZ 
  71.          Height          =   195
  72.          Left            =   300
  73.          TabIndex        =   12
  74.          Top             =   1260
  75.          Width           =   2535
  76.          _ExtentX        =   4471
  77.          _ExtentY        =   344
  78.          _Version        =   393216
  79.          LargeChange     =   2
  80.          Min             =   -20
  81.          Max             =   20
  82.          TickFrequency   =   4
  83.       End
  84.       Begin VB.Label lblZ 
  85.          Alignment       =   2  'Center
  86.          BackStyle       =   0  'Transparent
  87.          Height          =   255
  88.          Left            =   2940
  89.          TabIndex        =   21
  90.          Top             =   1260
  91.          Width           =   555
  92.       End
  93.       Begin VB.Label lblY 
  94.          Alignment       =   2  'Center
  95.          BackStyle       =   0  'Transparent
  96.          Height          =   255
  97.          Left            =   2940
  98.          TabIndex        =   20
  99.          Top             =   840
  100.          Width           =   555
  101.       End
  102.       Begin VB.Label lblX 
  103.          Alignment       =   2  'Center
  104.          BackStyle       =   0  'Transparent
  105.          Height          =   255
  106.          Left            =   2940
  107.          TabIndex        =   19
  108.          Top             =   420
  109.          Width           =   555
  110.       End
  111.       Begin VB.Label Label1 
  112.          BackStyle       =   0  'Transparent
  113.          Caption         =   "Z"
  114.          Height          =   255
  115.          Index           =   2
  116.          Left            =   120
  117.          TabIndex        =   9
  118.          Top             =   1260
  119.          Width           =   135
  120.       End
  121.       Begin VB.Label Label1 
  122.          BackStyle       =   0  'Transparent
  123.          Caption         =   "Y"
  124.          Height          =   255
  125.          Index           =   1
  126.          Left            =   120
  127.          TabIndex        =   8
  128.          Top             =   840
  129.          Width           =   135
  130.       End
  131.       Begin VB.Label Label1 
  132.          BackStyle       =   0  'Transparent
  133.          Caption         =   "X"
  134.          Height          =   255
  135.          Index           =   0
  136.          Left            =   120
  137.          TabIndex        =   7
  138.          Top             =   420
  139.          Width           =   135
  140.       End
  141.    End
  142.    Begin VB.CommandButton cmdExit 
  143.       Cancel          =   -1  'True
  144.       Caption         =   "E&xit"
  145.       Height          =   375
  146.       Left            =   5760
  147.       TabIndex        =   5
  148.       Top             =   3960
  149.       Width           =   1395
  150.    End
  151.    Begin VB.Frame Frame1 
  152.       Caption         =   "DirectMusic Segments"
  153.       Height          =   1995
  154.       Left            =   60
  155.       TabIndex        =   0
  156.       Top             =   180
  157.       Width           =   7095
  158.       Begin VB.CommandButton cmdSeg 
  159.          Caption         =   "Rude Awakening"
  160.          Height          =   315
  161.          Index           =   3
  162.          Left            =   120
  163.          TabIndex        =   4
  164.          Top             =   1500
  165.          Width           =   1395
  166.       End
  167.       Begin VB.CommandButton cmdSeg 
  168.          Caption         =   "Mumble"
  169.          Height          =   315
  170.          Index           =   2
  171.          Left            =   120
  172.          TabIndex        =   3
  173.          Top             =   1080
  174.          Width           =   1395
  175.       End
  176.       Begin VB.CommandButton cmdSeg 
  177.          Caption         =   "Snore"
  178.          Height          =   315
  179.          Index           =   1
  180.          Left            =   120
  181.          TabIndex        =   2
  182.          Top             =   660
  183.          Width           =   1395
  184.       End
  185.       Begin VB.CommandButton cmdSeg 
  186.          Caption         =   "Lullaby"
  187.          Height          =   315
  188.          Index           =   0
  189.          Left            =   120
  190.          TabIndex        =   1
  191.          Top             =   240
  192.          Width           =   1395
  193.       End
  194.       Begin VB.Label lbl 
  195.          BackStyle       =   0  'Transparent
  196.          Caption         =   "Segment file.  Stops all sound on audio path.  Plays as primary segment."
  197.          Height          =   255
  198.          Index           =   3
  199.          Left            =   1620
  200.          TabIndex        =   16
  201.          Top             =   1560
  202.          Width           =   5295
  203.       End
  204.       Begin VB.Label lbl 
  205.          BackStyle       =   0  'Transparent
  206.          Caption         =   "Wave file.  Overlaps if pressed twice.  Plays as secondary segment."
  207.          Height          =   255
  208.          Index           =   2
  209.          Left            =   1620
  210.          TabIndex        =   15
  211.          Top             =   1140
  212.          Width           =   5295
  213.       End
  214.       Begin VB.Label lbl 
  215.          BackStyle       =   0  'Transparent
  216.          Caption         =   "Segment file.  Overlaps if pressed twice.  Plays as secondary segment."
  217.          Height          =   255
  218.          Index           =   1
  219.          Left            =   1620
  220.          TabIndex        =   14
  221.          Top             =   720
  222.          Width           =   5295
  223.       End
  224.       Begin VB.Label lbl 
  225.          BackStyle       =   0  'Transparent
  226.          Caption         =   "Segment file.  Starts over if pressed twice.  Plays as primary segment."
  227.          Height          =   255
  228.          Index           =   0
  229.          Left            =   1620
  230.          TabIndex        =   13
  231.          Top             =   300
  232.          Width           =   5295
  233.       End
  234.    End
  235. Attribute VB_Name = "frmSimple"
  236. Attribute VB_GlobalNameSpace = False
  237. Attribute VB_Creatable = False
  238. Attribute VB_PredeclaredId = True
  239. Attribute VB_Exposed = False
  240. Option Explicit
  241. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  242. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  243. '  File:       frmSimple.frm
  244. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  245. Private dx As New DirectX8
  246. Private dmPerf As DirectMusicPerformance8
  247. Private dmLoad As DirectMusicLoader8
  248. Private dmPath As DirectMusicAudioPath8
  249. Private dmSeg(0 To 3) As DirectMusicSegment8
  250. Private sMediaFolder As String
  251. Private Sub cmdExit_Click()
  252.     Unload Me
  253. End Sub
  254. Private Sub cmdSeg_Click(Index As Integer)
  255.     If Not (dmSeg(Index) Is Nothing) Then
  256.         If Index = 0 Then
  257.             'Lullaby theme. This should play as a primary segment.
  258.             dmPerf.PlaySegmentEx dmSeg(Index), DMUS_SEGF_DEFAULT, 0, Nothing, dmPath
  259.         ElseIf Index = 3 Then
  260.             'Rude awakening. Notice that this also passes the audio path in pFrom, indicating that
  261.             'all segments currently playing on the audio path should be stopped at the exact time
  262.             'this starts.
  263.             dmPerf.PlaySegmentEx dmSeg(Index), 0, 0, dmPath, dmPath
  264.         ElseIf Index < 3 Then
  265.             'Sound effects. These play as secondary segments so they can be triggered multiple
  266.             'times and will layer on top.
  267.             dmPerf.PlaySegmentEx dmSeg(Index), DMUS_SEGF_SECONDARY Or DMUS_SEGF_DEFAULT, 0, , dmPath
  268.         End If
  269.     End If
  270. End Sub
  271. Private Sub Form_Load()
  272.     SetPosition
  273.     InitAudio
  274. End Sub
  275. Private Sub InitAudio()
  276.     On Error GoTo FailedInit
  277.     Dim dma As DMUS_AUDIOPARAMS
  278.     'Create our objects
  279.     Set dmPerf = dx.DirectMusicPerformanceCreate
  280.     Set dmLoad = dx.DirectMusicLoaderCreate
  281.     'Initialize our audio
  282.     dmPerf.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dma
  283.     Set dmPath = dmPerf.CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D, 64, True)
  284.     sMediaFolder = FindMediaDir("audiopath1.sgt")
  285.     If sMediaFolder = vbNullString Then sMediaFolder = AddDirSep(CurDir)
  286.     dmLoad.SetSearchDirectory sMediaFolder
  287.     'Now load the segments
  288.     Set dmSeg(0) = dmLoad.LoadSegment(sMediaFolder & "audiopath1.sgt")
  289.     Set dmSeg(1) = dmLoad.LoadSegment(sMediaFolder & "audiopath2.sgt")
  290.     Set dmSeg(2) = dmLoad.LoadSegment(sMediaFolder & "audiopath3.wav")
  291.     Set dmSeg(3) = dmLoad.LoadSegment(sMediaFolder & "audiopath4.sgt")
  292.     'Download our segments onto the audio path
  293.     Dim lCount As Long
  294.     For lCount = 0 To 3
  295.         dmSeg(lCount).Download dmPath
  296.     Next
  297.     Exit Sub
  298. FailedInit:
  299.     MsgBox "Could not initialize DirectMusic." & vbCrLf & "This sample will exit.", vbOKOnly Or vbInformation, "Exiting..."
  300.     Unload Me
  301. End Sub
  302. Private Sub Cleanup()
  303.     Dim lCount As Long
  304.         
  305.     'Unload all of our segments
  306.     For lCount = 0 To 3
  307.         If Not (dmSeg(lCount) Is Nothing) Then
  308.             dmSeg(lCount).Unload dmPath
  309.         End If
  310.         Set dmSeg(lCount) = Nothing
  311.     Next
  312.     'Destroy everything
  313.     Set dmPath = Nothing
  314.     dmPerf.CloseDown
  315.     Set dmPerf = Nothing
  316.     Set dmLoad = Nothing
  317. End Sub
  318. Private Sub SetPosition()
  319.     Dim dsb As DirectSound3DBuffer8
  320.     If Not (dmPath Is Nothing) Then
  321.         'First, get the 3D interface from the buffer by using GetObjectInPath.
  322.         Set dsb = dmPath.GetObjectinPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_ALL, 0, IID_DirectSound3DBuffer)
  323.         If Not (dsb Is Nothing) Then
  324.             'Then, set the coordinates
  325.             dsb.SetPosition sldX.Value, sldY.Value, SldZ.Value, DS3D_IMMEDIATE
  326.         End If
  327.     End If
  328.     'Update the text boxes as well
  329.     lblX.Caption = CStr(sldX.Value)
  330.     lblY.Caption = CStr(sldY.Value)
  331.     lblZ.Caption = CStr(SldZ.Value)
  332. End Sub
  333. Private Sub Form_Unload(Cancel As Integer)
  334.     Cleanup
  335. End Sub
  336. 'Update the 3D Positions when any of the scroll bars move
  337. Private Sub sldX_Click()
  338.     SetPosition
  339. End Sub
  340. Private Sub sldX_Scroll()
  341.     SetPosition
  342. End Sub
  343. Private Sub sldY_Click()
  344.     SetPosition
  345. End Sub
  346. Private Sub sldY_Scroll()
  347.     SetPosition
  348. End Sub
  349. Private Sub SldZ_Click()
  350.     SetPosition
  351. End Sub
  352. Private Sub SldZ_Scroll()
  353.     SetPosition
  354. End Sub
  355.